package com.ermao.mymes.web.config;

import io.swagger.annotations.ApiModel;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author Ermao
 * Date: 2022/5/12 18:07
 */
@Component
@EnableOpenApi
@ApiModel
public class SwaggerConfig {
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("用户端接口文档")
				.pathMapping("/")
				//定义是否开启Swagger，false是关闭，可以通过变量去控制，线上关闭
				.enable(true)
				//配置文档的元信息
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.ermao.mymes.web.controller"))
				//正则匹配请求路径，并分配到当前项目组
				//.paths(PathSelectors.ant("/api/**"))
				.build();
	}

	/**
	 * 设置api文档的详细信息
	 */
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("mymes 平台")
				.description("消息推送接口接口文档")
				.version("v1.0")
				.build();
	}
}
